package com.cm.bi;

import com.cm.order.Order;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class History {

    private BigDecimal income = BigDecimal.ZERO;

    private Map<String, Integer> soldDrinks = new HashMap<>();

    public void statistic(Order order) {
        income = income.add(BigDecimal.valueOf(order.getDrink().getPrice()));
        String drinkCode = order.getDrink().getCode();
        int historyNum = soldDrinks.get(drinkCode) == null ? 0 : soldDrinks.get(drinkCode);
        soldDrinks.put(drinkCode, ++historyNum);
    }

    public BigDecimal getIncome() {
        return income;
    }

    public Map<String, Integer> getSoldDrinks() {
        return soldDrinks;
    }

    @Override
    public String toString() {
        return "History{" +
                "total income=" + income +
                 " Euros, com.cm.drinks sold=" + soldDrinks +
                '}';
    }
}
